<?php

namespace  Helper;

use Inhere\Validate\Validation;

class Validate
{
    static function check($uri,$params){
        $rule = [];

        switch ($uri){

            case "/admin/authority/create":
                $rule = [
                    ['pid, name ,route', 'required','msg' => "必填参数不能为空" ],
                    ['pid', 'int', 'min'=> 0 ,'msg'=> '上级ID必选'],
                    ['name', 'string', 'min'=> 1 ],
                    ['route', 'string', 'min'=> 1 ],
                    ['client_route', 'string', 'min'=> 1 ],
                ];
                break;
            case "/admin/authority/edit":
                $rule = [
                    ['pid, name ,route ,id', 'required' ,'msg' => "必填参数不能为空"],
                    ['pid', 'int', 'min'=> 0 ],
                    ['id', 'int', 'min'=> 0 ],
                    ['name', 'string', 'min'=> 1 ],
                    ['route', 'string', 'min'=> 1 ],
                    ['client_route', 'string', 'min'=> 1 ],
                ];
                break;
            case "/admin/customer/setCustomerInfo":
                $rule = [
                    ['id', 'required' ],
                    ['id', 'int', 'min'=> 0 ],
                    ['nick', 'string','length', 'max' => 20 ],
                    ['phone', 'string', 'length'=> 11 ],
                ];
                break;
            case "/admin/login/doLogin":
                $rule = [
                    ['username,password', 'required','msg' => "必填参数不能为空" ],
                    ['username', 'string','length', 'max' => 20 ],
                    ['password', 'string','length', 'max' => 20 ],
                ];
                break;
            case "/admin/problem/index":
                $rule = [
                    ['platform_id', 'required' ,'msg' => "必填参数不能为空"],
                    ['platform_id', 'int', 'min'=> 0 ],
                ];
                break;
            case "/admin/problem/create":
                $rule = [
                    ['title', 'required' ,'msg' => "必填参数不能为空"],
                    ['title', 'string','length', 'max' => 50 ],
                    ['is_show', 'in', [0,1] ,'default' => 0],
                    ['platform_id', 'int', 'min'=> 0 ],
                ];
                break;
            case "/admin/problem/edit":
                $rule = [
                    ['title,id', 'required','msg' => "必填参数不能为空" ],
                    ['id', 'int', 'min'=> 0 ],
                    ['title', 'string','length', 'max' => 50 ],
                    ['is_show', 'in', [0,1] ,'default' => 0],
                    ['platform_id', 'int', 'min'=> 0 ],
                ];
                break;

            case "/admin/platform/create":
                $rule = [
                    ['name', 'required' ,'msg' => "必填参数不能为空"],
                    ['name', 'string','length', 'max' => 15 ],
                    ['secret', 'string','length', 'max' => 32 ,'default' => md5(time())],
                    ['state', 'in', [0,1] ,'default' => 1],
                ];
                break;

            case "/admin/platform/edit":
                $rule = [
                    ['name,id', 'required','msg' => "必填参数不能为空" ],
                    ['id', 'int', 'min'=> 0 ],
                    ['name', 'string','length', 'max' => 15 ],
                    ['secret', 'string','length', 'max' => 32 ],
                    ['state', 'in', [0,1] ,'default' => 1],
                ];
                break;


            case "/admin/role/create":
                $rule = [
                    ['name,authority_ids', 'required' ,'msg' => "必填参数不能为空"],
                    ['name', 'string','length', 'max' => 10 ],
                    ['authority_ids', 'string','length' ],
                ];
                break;

            case "/admin/role/edit":
                $rule = [
                    ['name,authority_ids,id', 'required' ,'msg' => "必填参数不能为空"],
                    ['id', 'int', 'min'=> 0 ],
                    ['name', 'string','length', 'max' => 10 ],
                    ['authority_ids', 'string','length','max' => 255 ],
                ];
                break;
            case "/admin/session/getHistoryMessge":
                $rule = [
                    ['sessid,', 'required' ,'msg' => "必填参数不能为空"],
                    ['sessid', 'int', 'min'=> 0 ],
                    ['page', 'int', 'min'=> 0 ,'default' =>1],
                    ['page_size', 'int', 'min'=> 0 ,'default' =>20],

                ];
                break;
            case "/admin/session/sendMsg":
                $rule = [
                    ['accept_uid,sessid,content,type', 'required','msg' => "必填参数不能为空" ],
                    ['sessid', 'int', 'min'=> 0 ],
                    ['accept_uid', 'int', 'min'=> 0 ],
                    ['type', 'in', [1,2,3] ,'default' => 1],
                    ['content', 'string','length', 'max' => 255 ,'msg'=> '消息内容太长'],

                ];
                break;
            case "/admin/session/close":
                $rule = [
                    ['uid,sessid', 'required' ,'msg' => "必填参数不能为空"],
                    ['sessid', 'int', 'min'=> 0 ],
                    ['uid', 'int', 'min'=> 0 ],

                ];
                break;
            case "/admin/user/index":
                $rule = [
                    ['platform_id', 'required' ,'msg' => "必填参数不能为空"],
                    ['platform_id', 'int', 'min'=> 0 ],
                ];
                break;
            case "/admin/user/create":
                $rule = [
                    ['username,password,phone,nick,max_service_num,role_id,problem_ids,platform_id', 'required','msg' => "必填参数不能为空" ],
                    ['username', 'string','length', 'max' => 20 ,'msg'=> '账号必填'],
                    ['password', 'string','length', 'max' => 32,'msg'=> '密码必填' ],
                    ['phone', 'string', 'length'=> 11 ,'msg'=> '手机号码必填' ],
                    ['nick', 'string', 'length', 'max' => 16,'msg'=> '昵称必填' ],
//                    ['avatar', 'string', 'length', 'max' => 255 ],
                    ['wechat', 'string', 'length', 'max' => 32 ],
                    ['qq', 'string', 'length', 'max' => 15 ],
                    ['email', 'email'],
                    ['max_service_num', 'int', 'min'=> 1 ,'msg'=> '最大接待数必填' ],
                    ['role_id', 'int', 'min'=> 1 ,'msg'=> '角色必选' ],
                    ['problem_ids','string','length','max' => 255,'msg'=> '绑定问题必选一个' ],
                    ['state', 'in', [0,1] ,'default' =>1,'msg'=> '状态必选' ],
                    ['platform_id', 'int', 'min'=> 1 ,'msg'=> '平台必选'  ],

                ];
                break;

            case "/admin/user/edit":
                $rule = [
                    ['id,username,phone,nick,max_service_num,role_id,problem_ids,platform_id', 'required' ,'msg' => "必填参数不能为空"],
                    ['id', 'int', 'min'=> 0 ],
                    ['username', 'string','length', 'max' => 20 ],
                    ['password', 'string','length', 'max' => 32 ],
                    ['phone', 'string', 'length'=> 11  ],
                    ['nick', 'string', 'length', 'max' => 16 ],
//                    ['avatar', 'string', 'length', 'max' => 255 ],
                    ['wechat', 'string', 'length', 'max' => 32 ],
                    ['qq', 'string', 'length', 'max' => 15 ],
                    ['email', 'email'],
                    ['max_service_num', 'int', 'min'=> 1 ],
                    ['role_id', 'int', 'min'=> 1 ],
                    ['problem_ids','string','length','max' => 255],
                    ['state', 'in', [0,1] ,'default' =>1],
                    ['platform_id', 'int', 'min'=> 1 ],
                ];
                break;
            case "/admin/user/editInfo":
                $rule = [
                    ['id', 'required','msg' => "必填参数不能为空" ],
                    ['id', 'int', 'min'=> 0 ],
                    ['password', 'string','length', 'max' => 32 ],
                    ['phone', 'string', 'length'=> 11  ],
                    ['nick', 'string', 'length', 'max' => 16 ],
//                    ['avatar', 'string', 'length', 'max' => 255 ],
                    ['wechat', 'string', 'length', 'max' => 32 ],
                    ['qq', 'string', 'length', 'max' => 15 ],
                    ['email', 'email'],

                ];
                break;
            case "/admin/workOrder/index":
                $rule = [
                    ['platform_id', 'required','msg' => "必填参数不能为空" ],
                    ['platform_id', 'int', 'min'=> 0 ],
                    ['page',  'int'  ,'default' =>1],
                    ['page_size',  'int'  ,'default' =>20],
                ];
                break;
            case "/admin/workOrder/create":
                $rule = [
                    ['title,content,state,platform_id', 'required','msg' => "必填参数不能为空" ],
                    ['title', 'string','length', 'max' => 50 ],
                    ['content', 'string'],
                    ['remark', 'string'],
                    ['state', 'in', [0,-1,1] ,'default' =>0],
                    ['platform_id', 'int', 'min'=> 0 ],

                ];
//                var_dump('rule',$rule);
                break;

            case "/admin/workOrder/edit":
                $rule = [
                    ['id,title,content,state', 'required','msg' => "必填参数不能为空" ],
                    ['id', 'int', 'min'=> 0 ],
                    ['title', 'string','length', 'max' => 50 ],
                    ['content', 'string'],
                    ['remark', 'string'],
                    ['state', 'in', [0,-1,1] ,'default' =>0],
                ];
                break;
            case "/admin/quickPelay/create":
                $rule = [
                    ['content', 'required' ,'msg' => "必填参数不能为空"],
                    ['content', 'string','length', 'max' => 255],
                ];
                break;
            case "/admin/quickPelay/edit":
                $rule = [
                    ['id,content', 'required' ,'msg' => "必填参数不能为空"],
                    ['id', 'int', 'min'=> 0 ],
                    ['content', 'string','length', 'max' => 255],
                ];
                break;

            case "/admin/messageBoard/edit":
                $rule = [
                    ['id,is_read', 'required' ,'msg' => "必填参数不能为空"],
                    ['id', 'int', 'min'=> 0 ],
                    ['is_read', 'in', [1] ,'default' =>1],
                ];
                break;
            case "/admin/messageBoard/index":
                $rule = [
                    ['platform_id', 'required' ,'msg' => "必填参数不能为空"],
                    ['platform_id', 'int', 'min'=> 0 ],
                    ['page', 'int', 'min'=> 0 ,'default' =>1],
                    ['page_size', 'int', 'min'=> 0 ,'default' =>20],
                ];
                break;
            case "/admin/session/setRead":
                $rule = [
                    ['sessid,is_read', 'required','msg' => "必填参数不能为空" ],
                    ['sessid', 'int', 'min'=> 1 ],
                    ['is_read', 'in', [1] ,'default' => 1],
                ];
                break;
            case "/v1/customer/createCustomer":
                $rule = [
                    ['u,from,device,p', 'required' ],
                    ['u', 'string','length', 'max' => 64 ],
                    ['from', 'in', [1,2] ,'default' => 1],
                    ['device', 'in', [1,2] ,'default' => 1],
                    ['p', 'string','length', 'max' => 32 ],
                    ['account', 'string','length', 'max' => 50 ],
                ];
                break;

            case "/v1/session/sendMsg":
                $rule = [
                    ['accept_uid,sessid,content,type', 'required' ],
                    ['sessid', 'int', 'min'=> 0 ],
//                    ['uid', 'int', 'min'=> 0 ],
                    ['accept_uid', 'int', 'min'=> 0 ],
                    ['type', 'in', [1,2,3] ,'default' => 1],
                    ['content', 'string','length', 'max' => 255,'msg'=> '消息不能太长' ],

                ];
                break;
            case "/v1/session/getHistoryMessge":
                $rule = [
                    ['sessid,', 'required' ],
                    ['sessid', 'int', 'min'=> 0 ],
                    ['page', 'int', 'min'=> 0 ,'default' =>1],
                    ['page_size', 'int', 'min'=> 0 ,'default' =>20],
                ];
                break;
            case "/v1/select/submitProblem":
                $rule = [
                    ['problem_id,p', 'required' ],
                    ['problem_id', 'int', 'min'=> 0 ],
                    ['p', 'string','length', 'max' => 32 ],
                ];
                break;
            case "/v1/select/selectKF":
                $rule = [
                    ['auid', 'required' ],
                    ['auid', 'int', 'min'=> 0 ],
                ];
                break;
            case "/v1/messageBoard/create":
                $rule = [
                    ['content,platform_id', 'required' ],
                    ['platform_id', 'string', 'max'=> 32 ],
                    ['content', 'string','length', 'max' => 255 ,'msg'=> '留言内容太长' ],
                ];
                break;
            case "/v1/problem/getProblem":
                $rule = [
                    ['p', 'required' ],
                    ['p', 'string','length', 'max' => 32 ],
                ];
                break;
        }


        $Valid = Validation::check($params,$rule);


        return $Valid;

    }
}